package server.web;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import server.domain.AjaxResult;
import server.domain.Area;
import server.domain.Page;
import server.service.AreaService;

@Controller
@RequestMapping("/area")
public class AreaController {
	@Autowired
	private AreaService service;
	
	@RequestMapping("/page")
	@ResponseBody
	public Page<Area> findPage(
			@RequestParam(name = "page", defaultValue = "1") Integer page,
			@RequestParam(name = "size", defaultValue = "10") Integer size) {
		
		return service.findPage(page, size);
	}
	
	@RequestMapping("/upload")
	@ResponseBody
	public AjaxResult upload(@RequestParam("excel") MultipartFile file) throws IllegalStateException, IOException {
//		System.out.println(file.getOriginalFilename());
		
		System.out.println(file.getSize());
		// file.transferTo(new File("D:\\" + file.getOriginalFilename()));
		// 把文件里面的区域信息解析出来，存到数据库里面去
		
		service.importExel(file);

		return AjaxResult.success();
	}
	
}
